package com.xius;

import cn.hutool.cron.CronUtil;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;

/**
 * sping boot 初始化完成后需要的操作
 */
public class ApplicationStartup implements ApplicationListener<ContextRefreshedEvent> {

    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        //设置秒级支持
        CronUtil.setMatchSecond(true);
        //开启定时任务
        boolean started = CronUtil.getScheduler().isStarted();
        if(started){
            CronUtil.stop();
        }
        CronUtil.start(true);
        ApplicationContext applicationContext = contextRefreshedEvent.getApplicationContext();
        //new SpringUtil().setApplicationContext(applicationContext);
        String[] definitionNames = applicationContext.getBeanDefinitionNames();
        System.out.println("spring容器注入了:" + definitionNames.length);
        /*for (String name : definitionNames) {
            System.out.println(name);
        }*/

}

}
